#version 130

uniform mat4 matrix_projection;
uniform mat4 matrix_world;
uniform mat4 matrix_view;

uniform mat4 matrix_bones[64];

in vec4 vertices;
in ivec4  bones;
in vec4 bone_blends;


vec4 eval_skeleton_vector (ivec4 bones, vec4 blends, vec4 vec)
{
	return
		(matrix_bones[bones.x] * vec) * blends.x +
		(matrix_bones[bones.y] * vec) * blends.y +
		(matrix_bones[bones.z] * vec) * blends.z +
		(matrix_bones[bones.w] * vec) * blends.w;
}


void main(void)
{
	gl_Position = matrix_projection * matrix_view *  matrix_world * eval_skeleton_vector (bones, bone_blends, vertices);
}
